/****************************************************************************
 *  _____       ______  _____
 * |_   _|     |  ____|/ ____|
 *   | |  _ __ | |__  | (___    Institute of Embedded Systems
 *   | | | '_ \|  __|  \___ \   Zürcher Hochschule für Angewandte
 *  _| |_| | | | |____ ____) |  Wissenschaften
 * |_____|_| |_|______|_____/   8401 Winterthur, Switzerland
 *
 ****************************************************************************
 *
 * @version $Rev: 522 $
 * @author  $Author: mcrescenti $
 * @date    $Date: 2014-08-20 11:51:39 +0200 (mer., 20 août 2014) $
 *
 ***************************************************************************/

#ifndef __HCPP_CONFIG_H__
#define __HCPP_CONFIG_H__

/*** AVALON - not set by ptp2_default.h *************************************/
#define USE_AVALON_REGISTER_USER0                           0       /* TODO: deprecated? */
#define USE_AVALON_DATA_CHECK                               0
#define USE_AVALON_BUS_WAIT                                 0       /**< NIOS2 system clock = 125 MHz = 8 ns per instruction (nop) */
#define AVALON_BUS_WAIT_TIME                                125     /**< 125 x 8 ns = 1 us */

/*** ENET *******************************************************************/
#define ENET_RX_DELAY                                       8200    /* 8800 */
#define ENET_TX_DELAY                                       125     /* 1000 */
#define ENET_RX_DELAY_SLAVE                                 0
#define ENET_TX_DELAY_SLAVE                                 0

/*** SYSCONF ****************************************************************/
#define SYSCONF_SYSID_TCC                                   0x00004328
#define SYSCONF_SYSID_DE115                                 0x00e6be5b
#define SYSCONF_DELAY_RESP_TO_ALL                           true

/*** PROFILE ****************************************************************/
#define PTP2_PROFILE                                        PTP2_PROFILE_ITU_T_G_8265_1

/*** OSCILLOQUARTZ - not set by ptp2_default.h ******************************/
#define USE_OSCILLOQUARTZ_SETTINGS                          1
#define USE_PTP2_DATASET_HARDWARE_REGISTER_READ             0

#define BOARD_SN                                            4
#define BOARD_SR_NR                                         0x00,BOARD_SN
#define OSA_MAC_ADD_HEAD_1                                  0x00,0x01,0x20
#define OSA_MAC_ADD_HEAD_2                                  0x02
#define OSA_MAC_ADD_HEAD                                    OSA_MAC_ADD_HEAD_1,OSA_MAC_ADD_HEAD_2

#define OSA_SUBNET                                          10,16,4         // or 172.21.5
#define INES_SUBNET                                         10,41,250

/*** PORT *******************************************************************/


#define PTP2_PORT_VLAN_ENABLE                               false
#define PTP2_PORT_VLAN_VID                                  12
#define PTP2_PORT_VLAN_PCP                                  0x00

#if USE_OSCILLOQUARTZ_SETTINGS
/* IP address depends on serial number if working outside the OSA network */
#define PTP2_PORT_IP_USE_DHCP                               false
#define PTP2_PORT_IPV4_ADDRESS                              OSA_SUBNET,BOARD_SN
#define PTP2_PORT_IPV4_GATEWAY                              10,16,4,100     /* ??? */
#define PTP2_PORT_IPV4_NETMASK                              255,255,0,0
#define PTP2_PORT_IPV6_ADDRESS                              1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#define PTP2_PORT_MAC_ADDRESS                               OSA_MAC_ADD_HEAD,BOARD_SR_NR
#else
#define PTP2_PORT_IP_USE_DHCP                               true
#define PTP2_PORT_IPV4_ADDRESS                              10,41,10,10
#define PTP2_PORT_IPV4_GATEWAY                              10,41,0,5
#define PTP2_PORT_IPV4_NETMASK                              255,255,0,0
#define PTP2_PORT_IPV6_ADDRESS                              0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0xfe
#define PTP2_PORT_MAC_ADDRESS                               0xaa,0xbb,0xcc,0xdd,0xee,0xff
#endif

#define PTP2_PORT_MULTICAST_ADDRESS_TYPE                    PTP2_ADDRESS_IPV4

#define PTP2_PORT_MULTICAST_IPV4_PRIMARY_IP                 224,0,1,129
#define PTP2_PORT_MULTICAST_IPV4_PDELAY_IP                  224,0,0,107

#define PTP2_PORT_MULTICAST_IPV6_PRIMARY_IP                 0xff0e,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0181
#define PTP2_PORT_MULTICAST_IPV6_PDELAY_IP                  0xff02,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x006b

#define PTP2_PORT_MULTICAST_IPV4_PRIMARY_MAC                0x01,0x00,0x5e,0x00,0x01,0x81
#define PTP2_PORT_MULTICAST_IPV4_PDELAY_MAC                 0x01,0x00,0x5e,0x00,0x00,0x6b
#define PTP2_PORT_MULTICAST_IPV6_PRIMARY_MAC                0x33,0x33,0x00,0x00,0x01,0x81   /* not used */
#define PTP2_PORT_MULTICAST_IPV6_PDELAY_MAC                 0x33,0x33,0x00,0x00,0x00,0x6b   /* not used */
#define PTP2_PORT_MULTICAST_ETHER_PRIMARY_MAC               0x01,0x1b,0x19,0x00,0x00,0x00
#define PTP2_PORT_MULTICAST_ETHER_PDELAY_MAC                0x01,0x80,0xc2,0x00,0x00,0x0e

#define PTP2_DSCP_PTP_EVENT                                 0xB8
#define PTP2_DSCP_PTP_GENERAL                               0x00

/*** DEFAULT DATASET ********************************************************/
#define PTP2_DEFAULT_DS_TWO_STEP_CLOCK                      false
#if USE_OSCILLOQUARTZ_SETTINGS
#define PTP2_DEFAULT_DS_CLOCK_IDENTITY                      OSA_MAC_ADD_HEAD_1,0xff,0xfe,OSA_MAC_ADD_HEAD_2,BOARD_SR_NR
#else
#define PTP2_DEFAULT_DS_CLOCK_IDENTITY                      0xaa,0xbb,0xcc,0xff,0xfe,0xdd,0xee,0xff
#endif
#define PTP2_DEFAULT_DS_PORT_COUNT                          1
#define PTP2_DEFAULT_DS_CLOCK_CLASS                         0x06
#define PTP2_DEFAULT_DS_CLOCK_ACCURACY                      0x20
#define PTP2_DEFAULT_DS_CLOCK_VARIANCE                      0xFFFF
#define PTP2_DEFAULT_DS_PRIORITY1                           0x05
#define PTP2_DEFAULT_DS_PRIORITY2                           0x01
#define PTP2_DEFAULT_DS_DOMAIN_NUMBER                       1
#define PTP2_DEFAULT_DS_SLAVE_ONLY                          false
#define PTP2_DEFAULT_DS_UNICAST_MODE                        true
#define PTP2_DEFAULT_DS_SIGNALING_ENABLED                   true

/*** TIME PROPERTIES DATASET ************************************************/
#define PTP2_TIME_PROPERTIES_DS_CURRENT_UTC_OFFSET          35           /* TAI is ahead of UTC, in seconds */
#define PTP2_TIME_PROPERTIES_DS_CURRENT_UTC_OFFSET_VALID    true
#define PTP2_TIME_PROPERTIES_DS_LEAP59                      false
#define PTP2_TIME_PROPERTIES_DS_LEAP61                      false
#define PTP2_TIME_PROPERTIES_DS_TIME_TRACEABLE              true
#define PTP2_TIME_PROPERTIES_DS_FREQUENCY_TRACEABLE         true
#define PTP2_TIME_PROPERTIES_DS_PTP_TIMESCALE               true
#define PTP2_TIME_PROPERTIES_DS_TIME_SOURCE                 PTP2_TIME_SOURCE_INTERNAL_OSCILLATOR /* PTP2_TIME_SOURCE_ATOMIC_CLOCK */

/*** PORT DATASET ***********************************************************/
#define PTP2_PORT_DS_PORT_NUMBER                            1
#define PTP2_PORT_DS_PORT_STATE                             PTP2_PORT_STATE_INITIALIZING
#define PTP2_PORT_DS_LOG_MIN_DELAY_REQ_INTERVAL             4
#define PTP2_PORT_DS_PEER_MEAN_PATH_DELAY                   0
#define PTP2_PORT_DS_LOG_ANNOUNCE_INTERVAL                  1
#define PTP2_PORT_DS_ANNOUNCE_RECEIPT_TIMEOUT               3
#define PTP2_PORT_DS_FOREIGN_MASTER_THRESHOLD               2
#define PTP2_PORT_DS_FOREIGN_MASTER_TIME_WINDOW             4
#define PTP2_PORT_DS_LOG_SYNC_INTERVAL                      0
#define PTP2_PORT_DS_DELAY_MECHANISM                        PTP2_DELAY_MECHANISM_E2E
#define PTP2_PORT_DS_LOG_MIN_PDELAY_REQ_INTERVAL            0
#define PTP2_PORT_DS_VERSION_NUMBER                         2
#define PTP2_PORT_DS_ALTERNATE_MASTER                       false
#define PTP2_PORT_DS_PROFILE_SPECIFIC1                      false
#define PTP2_PORT_DS_PROFILE_SPECIFIC2                      false

/*** FOREIGN MASTER *********************************************************/
#define PTP2_ANNOUNCE_SEQ_NR_OVERFLOW_WINDOW_SIZE           10      /* Defines the window size for a seq nr overflow has to be an even value*/

/*** NODE TABLE *************************************************************/
#define PTP2_NODE_TABLE_LUT_WRITE_INTERVAL                  1000    /**< value in milliseconds */
#define PTP2_NODE_TABLE_CHECK_LEASE_DURATION_INTERVAL       2000    /**< value in milliseconds */

/*** LOG ********************************************************************/
#define PTP2_LOG                                            true

#define PTP2_LOG_LEVEL_MASTER                               PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_LOG                                  PTP2_LOG_VERBOSE
#define PTP2_LOG_LEVEL_HAL_ENET                             PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_HAL_TIMER                            PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_HAL_PTP_TIME                         PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_HAL_SLAVEMGM                         PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_HAL_SYSCONF                          PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_HAL_TOD                              PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_HAL_ESMC                             PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_FSM                                  PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_PORT                                 PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_TASK                                 PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_TASK_QUEUE                           PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_ETHERNET                      PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_ARP                           PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_IPV4                          PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_PACKET_IPV6                          PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_PACKET_ICMP                          PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_UDP                           PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_PACKET_PTP2                          PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_PACKET_PTP2_SIGNALING                PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_PTP2_ANNOUNCE                 PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_PACKET_ANALYZER                      PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_ASSEMBLER                     PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PING_TABLE                           PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_ARP_TABLE                            PTP2_LOG_ERROR
#define PTP2_LOG_LEVEL_NODE_TABLE                           PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_SHADOW_TABLE                         PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PROFILE                              PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_BMCA                                 PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_TOD                                  PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_DATASET_DEFAULT                      PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_DATASET_CURRENT                      PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_DATASET_PARENT                       PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_DATASET_TIMEPROP                     PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_DATASET_PORT                         PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_DATASET_FOREIGN_MASTER               PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_SPI_MASTER                           PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_SPI_SLAVE                            PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_PPS_PLL                              PTP2_LOG_DEBUG

#endif

